<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>后台管理</title>
    <link rel="stylesheet" type="text/css" href="/static/plugins/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="/static/plugins/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="/static/plugins/Hui-iconfont/1.0.8/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="/static/plugins/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="/static/admin/css/style.css" />

    <script type="text/javascript" src="/static/plugins/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="/static/plugins/layer/2.4/layer.js"></script>
    <script type="text/javascript" src="/static/plugins/h-ui/js/H-ui.js"></script>
    <script type="text/javascript" src="/static/plugins/h-ui.admin/js/H-ui.admin.page.js"></script>
    <script type="text/javascript" src="/static/admin/js/myfun.js"></script>
</head>

<body>
        <article class="cl pd-20">
            <div class="row cl bg-1 bk-gray">
                <span class="select-box inline ml-50">
                    <select name="cid" id="cid" class="select">
                        <option value="0" {eq name='cid' value="0" }selected{/eq}>所有栏目</option>
                        {foreach $categoryTree as $value}
                        <option value="{$value.id}" {eq name='cid' value="$value.id" }selected{/eq}>{$value.name}</option>
                        {notempty name="value.child"}
                        {foreach $value.child as $val}
                        <option value="{$val.id}" {eq name='cid' value="$val.id" }selected{/eq}>--{$val.name}</option>
                        {notempty name="val.child"}
                        {foreach $val.child as $vo}
                        <option value="{$vo.id}" {eq name='cid' value="$vo.id" }selected{/eq}>&nbsp;&nbsp;└ --{$vo.name}
                        </option>
                        {/foreach}
                        {/notempty}
                        {/foreach}
                        {/notempty}
                        {/foreach}
                    </select>
                </span>
                <input class="input-text" type="text" name="key" id="key" value="{$key}" style="width: 300px;">
                <button class="btn btn-success radius" type="button" name="search" id="search">搜索</button>
            </div>
            <div class="row cl mt-20">
                <table class="table table-border table-bordered table-bg">
                    <thead>
                        <tr class="text-c">
                            <th width="25px;">
                                <input type="checkbox" name="allcheck" value="">
                            </th>
                            <th width="80px;">文章ID</th>
                            <th>文章专题</th>
                            <th width="120px;">栏目</th>
                        </tr>
                    </thead>
                    <tbody>
                        {foreach $list as $val}
                        <tr class="text-c va-m">
                            <td>
                                <input type="checkbox" value="{$val.id}" name="checkbox[]" {if in_array($val['id'],
                                    $topicInfoAidList)}disabled checked{/if}>
                                <input type="hidden" name="cid[]" value="{$val.cid}">
                            </td>
                            <td>{$val.id}</td>
                            <td class="text-l">
                                <a href="#" title="浏览" target="_blank">{$val.title}</a>
                            </td>
                            <td>{$val.category_name}</td>
                        </tr>
                        {/foreach}
                    </tbody>
                </table>
                <div class="cl pd-5 bg-1 bk-gray mt-20 ">
                    <span class="r">{notempty name="list"}{$list->render()|raw}{/notempty}</span>
                </div>
            </div>
            <form action="{:url('topic_info/save', ['tid'=>$tid])}" method="post" class="form form-horizontal"
                id="form-admin-article">
                <div class="row cl">
                    <label class="form-label col-xs-4 col-sm-2">所属子专题</label>
                    <div class="formControls col-xs-8 col-sm-4">
                        <span class="select-box">
                            <select class="select" id="tsid" name="tsid">
                                <option value="0">不属于任何子专题</option>
                                {foreach $topicSun as $sun}
                                <option value="{$sun.id}">{$sun.title}</option>
                                {/foreach}
                            </select>
                        </span>
                    </div>
                </div>
                <input type="hidden" name="tid" id="tid" value="{$tid}">
                <div class="row cl">
                    <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                        <button type="button" class="btn btn-success radius" id="form-save" name="">推送至专题</button>
                        <button type="button" class="btn btn-default radius" onclick="layer_close()"
                            style="margin-left:20px;">取&nbsp;消</button>
                    </div>
                </div>
            </form>
        </article>

    <!--请在下方写此页面业务相关的脚本-->
    <script type="text/javascript">
        $("#search").click(function(){
            var cid = $("#cid").val();
            var key = $("#key").val();
            var tid = $("#tid").val();

            window.location.href = "/admin/topic_info/articleList?tid="+tid+"&cid="+cid+"&key="+key;
        })

        $("#form-save").click(function () {
            var checkbox = $('.text-c input[name="checkbox[]"]');
            var a_c_ids = new Array();
            checkbox.each(function (x) {
                if (this.checked && this.disabled == false) {
                    var cid = $(this).next('.text-c input[name="cid[]"]').val();
                    var a_c_id = {
                        'aid': this.value,
                        'cid': cid
                    };
                    a_c_ids.push(a_c_id);
                }
            });

            var tid = $("#tid").val();
            var tsid = $("#tsid").val();

            $.ajax({
                url: '{:url("topic_info/save")}',
                type: "post",
                data: {
                    'a_c_ids': a_c_ids,
                    'tid': tid,
                    'tsid': tsid
                },
                dataType: 'json',
                success: function (res) {
                    // console.log(res);
                    layer.msg(res.msg, {
                        icon: 1,
                        time: 1000
                    }, function () {
                        parent.location.reload(); // 父页面刷新
                        var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                        parent.layer.close(index);
                    });
                },
                error: function (res) {
                    layer.msg(res.msg, {
                        icon: 5,
                        time: 1000
                    });
                    return false;
                }
            });
        });

    </script>

</body>

</html>